package com.qf.android.huihui.adapter.information;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qf.android.huihui.R;
import com.qf.android.huihui.bean.SearchBean;

/**
 * Created by lx on 2017/1/12.
 */

public class SearchGridViewAdapter extends BaseAdapter {
    private SearchBean searchBean;
    private Context context;

    public SearchGridViewAdapter(SearchBean searchBean, Context context) {
        this.searchBean = searchBean;
        this.context = context;
    }

    @Override
    public int getCount() {
        return searchBean.getData().size();
    }

    @Override
    public Object getItem(int i) {
        return searchBean.getData().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
       ViewHolder holder=null;
        if(view==null){
            view= LayoutInflater.from(context).inflate(R.layout.search_grid_item,viewGroup,false);
            holder=new ViewHolder();
            holder.tv= (TextView) view.findViewById(R.id.grid_tv);
            view.setTag(holder);
        }
       else
        holder= (ViewHolder) view.getTag();
        holder.tv.setText(searchBean.getData().get(i).getName());
        return view;
    }
    class ViewHolder{
        private TextView tv;
    }

}
